<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Đặng Khánh Trung
 * Date: 11/7/12
 * Time: 10:59 AM
 * To change this template use File | Settings | File Templates.
 */
// No direct access
defined('_JEXEC') or die;

jimport('joomla.application.component.controllerform');

class VastControllerCongtrinh extends JControllerForm
{
    /**
     * Class constructor.
     *
     * @param   array  $config  A named array of configuration variables.
     *
     * @since	1.6
     */
    function __construct($config = array())
    {

        parent::__construct($config);
    }

    /**
     * Method override to check if you can add a new record.
     *
     * @param   array  $data  An array of input data.
     *
     * @return  boolean
     *
     * @since   1.6
     */
    protected function allowAdd($data = array())
    {
        // Initialise variables.
        $user = JFactory::getUser();
        $allow = null;

        $allow = $user->authorise('vast.hosocanbo.edit');

        if ($allow === null)
        {
            // In the absense of better information, revert to the component permissions.
            return parent::allowAdd();
        }
        else
        {
            return $allow;
        }
    }

    /**
     * Method override to check if you can edit an existing record.
     *
     * @param   array   $data  An array of input data.
     * @param   string  $key   The name of the key for the primary key.
     *
     * @return  boolean
     *
     * @since   1.6
     */
    protected function allowEdit($data = array(), $key = 'id')
    {
        // Initialise variables.
        $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
        $user = JFactory::getUser();
        $userId = $user->get('id');

        // Check general edit permission first.
        if ($user->authorise('vast.hosocanbo.edit', 'com_vast'))
        {
            return true;
        }

        // Since there is no asset tracking, revert to the component permissions.
        return parent::allowEdit($data, $key);
    }
}